package cn.tedu.orderservice.exception;

import cn.tedu.charging.common.response.JsonResult;
import cn.tedu.charging.common.response.StatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler
    public JsonResult doMethodArgumentNotValidException(MethodArgumentNotValidException ex){
        log.debug("异常信息::"+ex.getMessage());
        log.debug("异常原因:"+ex.getFieldError().getDefaultMessage());
        return new JsonResult(StatusCode.VALIDATION_NULL_ERROR,ex.getFieldError().getDefaultMessage());
    }
}
